package grape.house.rest.areainterval.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.house.rest.areainterval.form.AreaIntervalListForm;
import grape.house.service.areainterval.query.AreaIntervalListQuery;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.house.rest.areainterval.form.AreaIntervalCreateForm;
import grape.house.rest.areainterval.form.AreaIntervalUpdateForm;
import grape.house.rest.areainterval.form.AreaIntervalListPageForm;
import grape.house.rest.areainterval.vo.AreaIntervalVo;
import grape.house.rest.areainterval.mapper.AreaIntervalWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.house.service.areainterval.po.AreaInterval;
import grape.house.service.areainterval.api.IAreaIntervalService;
import java.util.List;
/**
 * <p>
 * 面积区间 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-09-17
 */
@RestController
@RequestMapping("/house/areainterval")
@Api(tags = "面积区间相关接口")
public class AreaIntervalController extends BaseController<AreaIntervalVo, AreaInterval> {

    @Autowired
    private AreaIntervalWebMapper currentWebMapper;
    @Autowired
    private IAreaIntervalService currentService;



     @ApiOperation("添加面积区间")
     @PreAuthorize("hasAuthority('areainterval:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public AreaIntervalVo create(@RequestBody @Valid AreaIntervalCreateForm cf) {
         AreaInterval po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询面积区间")
     @PreAuthorize("hasAuthority('areainterval:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public AreaIntervalVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除面积区间")
     @PreAuthorize("hasAuthority('areainterval:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新面积区间")
     @PreAuthorize("hasAuthority('areainterval:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public AreaIntervalVo update(@PathVariable String id,@RequestBody @Valid AreaIntervalUpdateForm uf) {
         AreaInterval po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("不分页查询面积区间")
    @PreAuthorize("hasAuthority('areainterval:single:list')")
    @GetMapping("/list")
    @ResponseStatus(HttpStatus.OK)
    public List<AreaIntervalVo> list(AreaIntervalListForm listForm) {
        AreaInterval po = currentWebMapper.formToPo(listForm);
        AreaIntervalListQuery areaIntervalListQuery = new AreaIntervalListQuery();
        areaIntervalListQuery.setPoQuery(po);
        return super.list(areaIntervalListQuery);
    }

    @ApiOperation("分页查询面积区间")
    @PreAuthorize("hasAuthority('areainterval:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<AreaIntervalVo> listPage(AreaIntervalListPageForm listPageForm) {
         AreaInterval po = currentWebMapper.formToPo(listPageForm);
        AreaIntervalListQuery areaIntervalListQuery = new AreaIntervalListQuery();
        areaIntervalListQuery.setPoQuery(po);
         return super.listPage(areaIntervalListQuery,listPageForm);
     }

}
